package com.yuexunit.operationman.nbsy.module.Patients.adapter;

import android.content.Intent;
import android.view.View;
import android.widget.AbsListView;

import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.module.OperationBeforeAndAfter.bean.BeforeAndAfterBean;
import com.yuexunit.operationman.nbsy.module.OperationBeforeAndAfter.ui.Act_OperationBeforeAndAfter_Main_Fast;

import org.kymjs.kjframe.widget.AdapterHolder;
import org.kymjs.kjframe.widget.KJAdapter;

import java.util.Collection;

/**
 * Created by 姚平 on 2015/11/22.
 */
public class PatientListAdapter extends KJAdapter<BeforeAndAfterBean.ObjectEntity> {

    public PatientListAdapter(AbsListView view, Collection mDatas, int itemLayoutId) {
        super(view, mDatas, itemLayoutId);
    }

    @Override
    public void convert(AdapterHolder adapterHolder, BeforeAndAfterBean.ObjectEntity item, boolean isScrolling) {
        adapterHolder.setText(R.id.patient_name, item.getName()!=null?item.getName():"");
        adapterHolder.setText(R.id.patient_bed, item.getBedNo());
        adapterHolder.setText(R.id.patient_hospital, item.getVisitNo());
        adapterHolder.setText(R.id.patient_age, item.getAge());
        adapterHolder.setText(R.id.patient_ward, "病区"+item.getLesion());
        if(item.getSex().equals("1")) {
            adapterHolder.setText(R.id.patient_sex, "男");
        }else if(item.getSex().equals("2"))
        {
            adapterHolder.setText(R.id.patient_sex, "女");
        }
        else {
            adapterHolder.setText(R.id.patient_sex, "不详");
        }
        //对item设置点击事件，跳转到病人详情界面
        onPicClick(adapterHolder.getConvertView(),item);
    }

    private void onPicClick(View view, final BeforeAndAfterBean.ObjectEntity item) {
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mCxt, Act_OperationBeforeAndAfter_Main_Fast.class);
                intent.putExtra("operationId",item.getOperationNo());
                mCxt.startActivity(intent);
            }
        });
    }
}
